*figure 3

cd "/Users/kevin/Dropbox/TZ ITNs"
set more off
set varabbrev off

use "constructed data/for_analysis.dta", clear

cd "/Users/kevin/Dropbox/TZ ITNs/plots"

lab var consumption_pc "Per capita consumption"


bys time_since_ucc: egen mean_consumption_pc=mean(consumption_pc)
twoway (lpoly consumption_pc time_since_ucc if time_since_ucc<-15 & sample==1, lcolor(black) clwidth(thick)) ///
 (lpoly consumption_pc time_since_ucc if time_since_ucc>15 & sample==1, ///
lcolor(black) clwidth(thick)) ///
(scatter mean_consumption_pc time_since_ucc, msize(vsmall) ///
 color(gray)) if (time_since_ucc>15 | time_since_ucc<-15) ///
 & sample==1, ///
 title(`variable label `y'', color(black)) xline(-15 15, lpattern(dash) lcolor(black)) ///
 legend(off) ylabel(, nogrid) xtitle(days since ITN distribution, size(medlarge)) ///
 ytitle(`y', size(medlarge)) yscale(r(0 1000000)) ///
subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ///
 ifcolor(white) ilcolor(white)) xlabel(-365(100)365) ylabel(500000 1500000) ytitle (consumption per capita) xline(-90 90, lpattern(dash) lcolor(gs12))
graph save Graph "consumption_pc.gph", replace

bys time_since_ucc: egen mean_age=mean(age)
twoway (lpoly age time_since_ucc if time_since_ucc<-15 & sample==1, lcolor(black) clwidth(thick)) ///
 (lpoly age  time_since_ucc if time_since_ucc>15 & sample==1, ///
lcolor(black) clwidth(thick)) ///
(scatter mean_age  time_since_ucc, msize(vsmall) ///
 color(gray)) if (time_since_ucc>15 | time_since_ucc<-15) ///
 & sample==1, ///
 title(`variable label `y'', color(black)) xline(-15 15, lpattern(dash) lcolor(black)) ///
 legend(off) ylabel(, nogrid) xtitle(days since ITN distribution, size(medlarge)) ///
 ytitle(age, size(medlarge)) yscale(r(0 50)) ///
subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ///
 ifcolor(white) ilcolor(white)) xlabel(-365(100)365) ylabel(10 20 30 40) xline(-90 90, lpattern(dash) lcolor(gs12))
graph save Graph "age.gph", replace


    foreach y in female urban {  
bys time_since_ucc: egen mean_`y'=mean(`y')
twoway (lpoly `y' time_since_ucc if time_since_ucc<-15 & sample==1, lcolor(black) clwidth(thick)) ///
 (lpoly `y' time_since_ucc if time_since_ucc>15 & sample==1, ///
lcolor(black) clwidth(thick)) ///
(scatter mean_`y' time_since_ucc, msize(vsmall) color(gray)) if (time_since_ucc>15 | time_since_ucc<-15) ///
 & sample==1, ///
 title(`variable label `y'', color(black)) xline(-15 15, lpattern(dash) lcolor(black)) ///
 legend(off) ylabel(, nogrid) xtitle(days since ITN distribution, size(medlarge)) ///
 ytitle(`y', size(medlarge)) yscale(r(0 1)) ///
subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ///
 ifcolor(white) ilcolor(white)) xlabel(-365(100)365) ylabel(0.2 0.4 0.6 0.8) xline(-90 90, lpattern(dash) lcolor(gs12))
graph save Graph "`y'.gph", replace
}

  graph combine "consumption_pc.gph" "female.gph" "age.gph" ///
"urban.gph", rows(2) cols(2) subtitle(, color(black) fcolor(white) ///
 lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
